package com.jilujia.domain.blog;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.NotEmpty;

import com.jilujia.framework.domain.PoEntity;
import com.jilujia.web.validator.BlogCatalogNotNull;

@Entity
@Table(name = "TB_BLOG")
@BlogCatalogNotNull
public class Blog implements PoEntity<Long>, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3026625819406565578L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	private Long regionId;

	@NotEmpty()
	@Column(nullable = false, length = 100)
	private String title;

	@NotEmpty()
	@Type(type = "text")
	@Column(nullable = false)
	private String content;

	@Column(length = 100)
	private String keywords;

	@Column(nullable = false)
	private Long userId;

	@NotNull
	@ManyToOne(optional = false)
	private BlogCatalog catalog;

	@NotNull
	@Enumerated(EnumType.STRING)
	@Column(nullable = false, length = 10)
	private BlogTypeEnum type = BlogTypeEnum.ORIGINAL;

	@Column(length = 100)
	private String originUrl;

	@Column(nullable = false)
	private Integer viewCount = 0;

	@Column(nullable = false)
	private Integer replyCount = 0;

	@NotNull
	@Column(nullable = false)
	private boolean asTop = false;

	@NotNull
	@Column(nullable = false)
	private boolean allowComment = true;

	@NotNull
	@Column(nullable = false)
	private boolean asDraft = true;

	@Temporal(TemporalType.TIMESTAMP)
	private Date postedDate;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date createdDate;

	@Temporal(TemporalType.TIMESTAMP)
	private Date modifyDate;

	private Long modifierId;

	public void processVo(Blog blogVo) {
		this.setId(blogVo.getId());
		this.setRegionId(blogVo.getRegionId());
		this.setType(blogVo.getType());
		this.setTitle(blogVo.getTitle());
		this.setCatalog(blogVo.getCatalog());
		this.setContent(blogVo.getContent());
		this.setKeywords(blogVo.getKeywords());
		this.setAllowComment(blogVo.getAllowComment());
		this.setAsTop(blogVo.getAsTop());
		this.setAsDraft(blogVo.getAsDraft());
		this.setOriginUrl(blogVo.getOriginUrl());
	}

	public Blog() {
		// this.setCreatedDate(new Date(System.currentTimeMillis()));
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public BlogCatalog getCatalog() {
		return catalog;
	}

	public void setCatalog(BlogCatalog catalog) {
		this.catalog = catalog;
	}

	public BlogTypeEnum getType() {
		return type;
	}

	public void setType(BlogTypeEnum type) {
		this.type = type;
	}

	public Long getRegionId() {
		return regionId;
	}

	public void setRegionId(Long regionId) {
		this.regionId = regionId;
	}

	public Integer getViewCount() {
		return viewCount;
	}

	public void setViewCount(Integer viewCount) {
		this.viewCount = viewCount;
	}

	public Integer getReplyCount() {
		return replyCount;
	}

	public void setReplyCount(Integer replyCount) {
		this.replyCount = replyCount;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getOriginUrl() {
		return originUrl;
	}

	public void setOriginUrl(String originUrl) {
		this.originUrl = originUrl;
	}

	public boolean getAsTop() {
		return asTop;
	}

	public void setAsTop(boolean asTop) {
		this.asTop = asTop;
	}

	public boolean getAllowComment() {
		return allowComment;
	}

	public void setAllowComment(boolean allowComment) {
		this.allowComment = allowComment;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public Long getModifierId() {
		return modifierId;
	}

	public void setModifierId(Long modifierId) {
		this.modifierId = modifierId;
	}

	public boolean getAsDraft() {
		return asDraft;
	}

	public void setAsDraft(boolean asDraft) {
		this.asDraft = asDraft;
	}

	public Date getPostedDate() {
		return postedDate;
	}

	public void setPostedDate(Date postedDate) {
		this.postedDate = postedDate;
	}

}